home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / NeXT-Icons / next-icon@gun.com / Apps / mail-notifier / mail-notifier2.rtfd / .notify next >
Encoding:
Text File  |  1994-03-09  |  7.9 KB  |  217 lines

  1. #! /bin/sh
  2. #######################################################
  3. # INTRODUCTION    (.notify was written by gbrown@alumni.caltech.edu  )
  4. #        ( and is in the public domain.  Tabs every 4 spaces)
  5. # This script plays a user-specified sound when mail is received.
  6. # The user can specify not to play sounds when
  7. #        * he is not logged in on the console.
  8. #         * the mail is from a mailing list or uninteresting person
  9. # Sounds play even when the user is not logged in, if desired.
  10. # The user can specify an additional sound to play when the word 'urgent' 
  11. #        appears in first 40 lines of the message (assuming the message isn't 
  12. #        from a mailing list or unintersting person in the kill list)
  13. # This script can also be used to control the 'vacation' program, allowing 
  14. #    the user to specify a list of people NOT to notify when the user is 
  15. #    on vacation.  It is a matter of courtesy to add mailing list to this
  16. #    list, since the people in the list don't care if you are on vacation.
  17. #######################################################
  18.  
  19. #######################################################
  20. # INSTALLATION
  21. # (0) 'chmod 707 <this file>', so that it is executable and not writable.
  22. # (1) Put this script somewhere permanent.
  23. # (2) Turn on the public sound server in "Preferences.app".  You will
  24. #    only hear sounds if the user logged in has his public sound server on.
  25. #    If you want to hear sounds when noone is logged on, root must have his
  26. #    public sound server turned on.
  27. # (3) You should customize the variables below, following the instructions.
  28. # (4) execute the following line, appropriately modified 
  29. #    echo '\<yourUsername>,"|<theCompletePathnameOfThisFile>"' > ~/.forward
  30. #         where <yourUsername> is your username and 
  31. #         <theCompletePathnameOfThisFile> is the complete
  32. #         pathname of this file.
  33. #######################################################
  34.  
  35. #######################################################
  36. # CUSTOMIZATION
  37. #     Change the variables below to reflect the
  38. # desired settings at your site.
  39. #######################################################
  40. username=gbrown
  41.     # your username
  42.     # Example: username=gbrown
  43.  
  44. mailSound=~gbrown/Library/Sounds/Glenn.snd
  45.     # the sound to play when mail arrives
  46.     # Example: mailSound=~gbrown/Library/Sounds/Glenn.snd
  47.     
  48. urgentSound=~gbrown/Library/Sounds/Urgent.snd
  49.     # an extra sound to play if mail is has the word 'urgent' in it
  50.     # Example: urgentSound=~gbrown/Library/Sounds/Urgent.snd
  51.  
  52. silentSenders="next-icon@ RTFusers@ omniweb-l@"
  53.     # senders whose mail will not generate sounds.  This
  54.     # is a good place to list mailing lists.  Case
  55.     # is unimporatant in this list.
  56.     # Example: silentSenders="next-icon@ RTFusers@ omniweb-l@"
  57.  
  58. playOnlyWhenOnConsole=YES
  59.     # if you only want sounds played when you are logged onto
  60.     # the console, this variable should be YES.  Otherwise, set
  61.     # it to anything else.
  62.     # Example: playOnlyWhenOnConsole=YES
  63.  
  64. onVacation=NO
  65.     # Edit your ~/.vacation.msg, run 'vacation -I' in your home directory,
  66.     # and set onVacation to YES (in that order) when you go on vacation.
  67.     # Set it to anything else when you return from vacation.
  68.     # 'man vacation' for more info, but DO NOT modify the .forward file
  69.     # as the man page says.  This script handles the forwarding itself.
  70.     # Example: onVacation=NO
  71.  
  72. dontTellOnVacation=${silentSenders}
  73.     # a space delimited list of senders you don't want to send vacation
  74.     # messages to.  Mailing lists are good should be
  75.     # listed here.  Case is unimporant here. Use $silentSenders if
  76.     # you want this list to be the same as the silentSenders list.
  77.     # Example: dontTellOnVacation=$silentSenders
  78.     # Example: dontTellOnVacation="next-icon@ RTFusers@ omniweb-l jerk@netcom.com"
  79.  
  80. buff=/tmp/.notify.$username.buff
  81. senders=/tmp/.notify.$username.senders
  82. ifonconsole=/tmp/.notify.$username.ifonconsole
  83.     # The above 3 variables should specify three files
  84.     # that this script can create. They should be in a
  85.     # directory that $username can write to.  If the files
  86.     # exist, they must be owned by $username and
  87.     # will be destroyed.
  88.     # Example: buff=/tmp/.notify.username.buff
  89.     #           senders=/tmp/.notify.$username.senders
  90.     #           ifonconsole=/tmp/.notify.$username.ifonconsole
  91.  
  92.     
  93. #######################################################
  94. # CODE
  95. #    Do not modify any code below this point unless you
  96. # really know what you are doing.
  97. #######################################################
  98.  
  99. ##########################
  100. # STARTUP CODE
  101. ##########################
  102.  
  103. homeDir=~$username    #the user's home directory
  104. # if the ifonconsole script is not installed,
  105. # install a copy if needed.
  106. #echo p=$playOnlyWhenOnConsole.
  107. if test ${playOnlyWhenOnConsole-YES} = YES # if we need the script
  108. then     
  109.     #echo checking if installed.
  110.     # if the $ifonconsole script is not installed, install it.
  111.     if test \! -f $ifonconsole && $ifonconsole $username /bin/false /bin/false
  112.     then
  113.         #echo installing
  114.         echo '#! /bin/sh'\                                                    >  $ifonconsole
  115.         echo '# This script has the syntax'\                                >> $ifonconsole
  116.         echo '#ifonconsole username oncommand [offcommand]'\                >> $ifonconsole
  117.         echo '# oncommand is executed if username is logged into the'\        >> $ifonconsole
  118.         echo '# console.  offcommand is run if not.  You should put '\        >> $ifonconsole
  119.         echo '# single quotes around the oncommand and offcommand in csh'\    >> $ifonconsole
  120.         echo '# or sh to make them single arguments.  The commands'\        >> $ifonconsole
  121.         echo '# are executed using sh.'\                                    >> $ifonconsole
  122.         echo 'if (who | fgrep console) | fgrep "$1" > /dev/null 2>&1;'\        >> $ifonconsole
  123.         echo 'then    '\                                                        >> $ifonconsole
  124.         echo '    ($2)'\                                                        >> $ifonconsole
  125.         echo 'else    '\                                                        >> $ifonconsole
  126.         echo '    ($3)'\                                                        >> $ifonconsole
  127.         echo 'fi    '\                                                        >> $ifonconsole
  128.         echo 'exit 0'\                                                        >> $ifonconsole
  129.         chmod a-w $ifonconsole        #make sure noone can change this file
  130.                                     #since we will execute it
  131.         chmod +x $ifonconsole        #make the file executable
  132.     fi
  133. fi
  134.  
  135. # copy the first screenful of the mail message to the buffer
  136. # for later perusal.
  137. head -40 > $buff
  138.  
  139. # put the lines that specify the sender into a file.
  140. # the To: and CC: lines are included because so messages to a mailing
  141. # list can also be detected.
  142. grep -i '^To:' $buff > $senders
  143. grep -i '^CC:' $buff >> $senders
  144. grep -i '^From:' $buff >> $senders
  145. #(echo; cat $buff) | grep -i '^From' >> $senders
  146. # From: can be on the first line causing the ^ to not match, so put a ^ at the beginning of
  147. # the file.
  148.  
  149. ##########################
  150. # SOUND PLAYING CODE
  151. ##########################
  152.  
  153. # Test for conditions that make us not want to play a sound
  154. for string in $silentSenders
  155. do
  156.     #echo \"$string\"
  157.     if grep -is $string < $senders 
  158.     then PLAYSOUND=NO; break; fi
  159. done
  160.  
  161. # Play the notification sound unless sound turned off above
  162. if test ${PLAYSOUND-YES} = YES
  163. then
  164.     if test ${playOnlyWhenOnConsole-YES} = YES
  165.     then
  166.         /usr/local/bin/ifonconsole gbrown /usr/bin/sndplay\ $mailSound
  167.     else
  168.         /usr/bin/sndplay $mailSound
  169.     fi
  170.     # See if the message is urgent and play sound if it is
  171.     if grep -i 'urgent' < $buff
  172.     then 
  173.         #echo The message is urgent.
  174.         if test ${playOnlyWhenOnConsole-YES} = YES
  175.         then
  176.             /usr/local/bin/ifonconsole gbrown /usr/bin/sndplay\ $urgentSound
  177.         else
  178.             /usr/bin/sndplay $urgentSound
  179.         fi
  180.     fi
  181. fi
  182.  
  183. ##########################
  184. # VACATION CODE
  185. ##########################
  186.  
  187. #echo entering vacation code
  188. if test ${onVacation-NO} = YES
  189. then
  190.     # Test for conditions that make us not want to play a sound and exit if such
  191.     # conditions are found.
  192.     for string in $dontTellOnVacation
  193.     do
  194.         #echo $string
  195.         # Don't make sounds if next-icon@ is in the 'To:' or 'CC:' line.
  196.         if grep -is $string < $buff 
  197.         then TELLONVACATION=NO; break; fi
  198.     done
  199.     
  200.     if test ${TELLONVACATION-YES} = YES
  201.     then
  202.         #echo going to homedir
  203.         #cd $homeDir
  204.         #echo calling vacation program
  205.         /usr/ucb/vacation $username < $buff
  206.     fi
  207. fi
  208.  
  209. ##########################
  210. # CLEANUP CODE
  211. ##########################
  212. rm $buff $senders
  213. exit 0
  214.  
  215. # This file is free, in the public domain, and offered without any warrantee whatsoever.